<?php
namespace Home\Model;
use  Think\Model;
class PayModel extends Model{
    
    protected $autoCheckFields =false;

      /**
     * 更改订单记录支付-1：微信支付； 2：支付宝，3：现金支付
     */
    function order_paid($out_trade_no,$total_fee,$pay_mode=0,$transaction_id='',$openid='') {
          $now_time=gmtime();
          $where['tran_no'] = $out_trade_no;
          $field = "*";//暂时不知道显示那几个字段
          $order_info = M("orders")->field($field)->where($where)->find();
          if(!$order_info) return false;

          if($order_info['status']==0)
          {    
                $total_amount=$order_info['total_amount'];
                $id=$order_info['id'];

                if($total_amount!=$total_fee)//金额不一致
                {
                  // echo '金额不一致';exit;
                  return false;
                }

                //改变支付状态
                $where = array();
                $where['id'] = $id;
                $update_data['status'] = 1;
                $update_data['pay_mode'] = $pay_mode;
                $update_data['transaction_id'] = $transaction_id;
                $update_data['xcx_openid'] = $openid;
                $update_data['payed_at'] = $now_time;
                $result = M("orders")->where($where)->save($update_data);
                if(!$result){return false;}
                else  return true;
          }
          else
          {
            return false;

          }
    }





}